#include<bits/stdc++.h>
using namespace std;
int t,ra=0,a[1000000],ans=0,n;
int judgee()
{
    int ansj=0;
    for(int i=1;i<=n;i++)
    {

        bool b=ra&(1<<(i-1));//b is the color of pi
        for(int j=i-1;j>=1;j--)
        {
            bool b2=(1<<(j-1))&ra;
            if(b2==b)
            {
                if(a[i]==a[j])
                {
                    ansj+=a[i];
                }
                break;
            }
        }
    }
    return ansj;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--)
    {
        ans=0;
        cin>>n;
        if(n>=18){cout<<0<<endl;continue;}
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(ra=0;ra<=(1<<n);ra++)
        {
            ans=max(judgee(),ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}
